//
//  VedioCell.swift
//  YueChat
//
//  Created by IMac on 2024/9/23.
//

import UIKit

class VedioCell: BaseChatCell {

    @IBOutlet weak var thumBg: UIImageView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override func baseCellHeight(message: DMCCMessage, chatType: Bool, mulSelect: Bool, isMySend: Bool) {
        
        message.msgCellWidth = 200;
        message.msgCellHeight = 160;
    }
    
    override func setMessage(_ message: DMCCMessage) {
        super.setMessage(message)
        
        var homeStr = NSHomeDirectory()
        homeStr = formatLocalUrl(filePath: homeStr)!
        if let videoContent = message.content as? OsnVideoMessageContent {
//            if videoContent.thumbnail == nil && videoContent.localPath.count > 0 {
//                videoContent.thumbnail = getFileThumbnailImage(from: videoContent.localPath)
//            }
//            self.showImg.sd_setImage(with: URL(fileURLWithPath: imgContent.localPath), placeholderImage: UIImage(named: "chatImgBg"))
            let path = getHomeFilePath(localPath: videoContent.localPath)
            if videoContent.localPath.count > 0 {
                let image = getFileThumbnailImage(from: path)
                if videoContent.localPath.contains(homeStr) {
                    self.thumBg.image = image
                }else if videoContent.localPath.hasSuffix(".MP4") || videoContent.localPath.hasSuffix(".mp4"){
                    self.thumBg.image = image
//                    self.thumBg.sd_setImage(with: url, placeholderImage: UIImage(named: "chatImgBg"))
                }else {
                    self.thumBg.image = UIImage(named: "failPhoto")
                }
            } else {
                self.thumBg.image = UIImage(named: "failPhoto")
                
                if videoContent.remoteUrl.hasSuffix(".zip") && videoContent.decKey.count > 0 {
                    self.thumBg.image = UIImage(named: "deckey")
                } else if videoContent.remoteUrl.hasSuffix(".zip") && videoContent.decKey.count == 0 {
                    self.thumBg.image = UIImage(named: "file_damage")
                }
            }
            
        }
    }
}
